﻿namespace OpenComposite.Repository.Services
{
	using System;
	using System.Collections.Generic;
	using System.Configuration;
	using System.Linq;
	using System.Text;

	using OpenComposite.EII.Repository;
	
	public class DomainConfigurationSection : ConfigurationSection
	{
		#region Public Members

		#region Properties

		[ConfigurationProperty("", IsDefaultCollection = true)]
		[ConfigurationCollection(typeof(DomainElementCollection),
			AddItemName="add", ClearItemsName="clear", RemoveItemName="remove")]
		public DomainElementCollection Items
		{
			get { return (DomainElementCollection)this[""]; }
			set { this[""] = value; }
		}

		#endregion Properties

		#endregion Public Members
	}

	public class DomainElement : ConfigurationElement
	{
		#region Public Members

		#region Properties

		[ConfigurationProperty("itemTypes", IsRequired = true)]
		public string ItemTypes
		{
			get { return (string)this["itemTypes"]; }
			set { this["itemTypes"] = value; }
		}

		[ConfigurationProperty("name", IsKey = true, IsRequired = true)]
		public string Name
		{
			get { return this["name"] as string; }
			set { this["name"] = value; }
		}

		#endregion Properties

		#endregion Public Members
	}

	public class DomainElementCollection : ConfigurationElementCollection
	{
		#region Indexers

		public DomainElement this[int index]
		{
			get { return (DomainElement)base.BaseGet(index); }
		}

		public new DomainElement this[string name]
		{
			get { return (DomainElement)base.BaseGet((object)name); }
		}

		#endregion Indexers

		#region Public Members

		#region Methods

		public void Add(DomainElement item)
		{
			base.BaseAdd(item);
		}

		public void Clear()
		{
			base.BaseClear();
		}

		public void Remove(DomainElement item)
		{
			base.BaseRemove(item.Name);
		}

		#endregion Methods

		#endregion Public Members

		#region Protected Members

		#region Methods

		protected override ConfigurationElement CreateNewElement()
		{
			return new DomainElement();
		}

		protected override object GetElementKey(ConfigurationElement element)
		{
			return ( (DomainElement)element ).Name;
		}

		#endregion Methods

		#endregion Protected Members

		public override ConfigurationElementCollectionType CollectionType
		{
			get
			{
				return ConfigurationElementCollectionType.AddRemoveClearMap;
			}
		}
	}
}